<?php defined('SYSPATH') OR die('No direct access allowed.');

abstract class Core_Lexico implements Constants {

	const D = "[0-9]";
	const L = "[A-Za-z]";
	const A = "[A-Za-z0-9]";
	const OP = "\+|\-|\*|/";
	const Q = ".";
	const ASS= "'";
	const ASD = "\"";
	const C = "[(!)(=)(>)(<)]";
	const EB = "[\ \	\r]";
	const NL = "[\
	]";
	
	protected $position;
	protected $input;
	
	protected $row;
	protected $col;
	
	public function __construct(){
		$this->row = 0;
		$this->col = 0;
	}
	
	public function setInput($input){
        $this->input = $input;
        $this->setPosition(0);
    }

    public function setPosition($pos){
        $this->position = $pos;
    }
    
    protected function isD($c){
    	$r = ereg(self::D, $c);
    	if($r==0){
    		return false;
    	}else{
    		return true;
    	}
    }
    
	protected function isL($c){
    	$r = ereg(self::L, $c);
    	if($r==0){
    		return false;
    	}else{
    		return true;
    	}
    }
    
   	protected function isA($c){
    	$r = ereg(self::A, $c);
    	if($r==0){
    		return false;
    	}else{
    		return true;
    	}
    }
    
   	protected function isOP($c){
    	$r = ereg(self::OP, $c);
    	if($r==0){
    		return false;
    	}else{
    		return true;
    	}
    }
    
   	protected function isQ($c){
    	$r = ereg(self::Q, $c);
    	if($r==0){
    		return false;
    	}else{
    		return true;
    	}
    }
    
   	protected function isASS($c){
    	$r = ereg(self::ASS, $c);
    	if($r==0){
    		return false;
    	}else{
    		return true;
    	}
    }
    
   	protected function isASD($c){
    	$r = ereg(self::ASD, $c);
    	if($r==0){
    		return false;
    	}else{
    		return true;
    	}
    }
    
   	protected function isC($c){
    	$r = ereg(self::C, $c);
    	if($r==0){
    		return false;
    	}else{
    		return true;
    	}
    }
   	protected function isEB($c){
    	$r = ereg(self::EB, $c);
    	if($r==0){
    		return false;
    	}else{
    		return true;
    	}
    }
	protected function isNL($c){
    	$r = ereg(self::NL, $c);
    	if($r==0){
    		return false;
    	}else{
    		return true;
    	}
    }
	protected function isEREG($er, $c){
    	$r = ereg($er, $c);
    	if($r==0){
    		return false;
    	}else{
    		return true;
    	}
    }
    
    
    
	
	/**
	 * Informa se ainda h� caracteres de entrada
	 * @return boolean
	 */
    protected function hasInput(){
    	//echo $this->position.'<'.strlen($this->input)."<br>\n";
        return $this->position < strlen($this->input);
    }

    /**
     * Retorna o proximo caractere e incremnta a posi��o
     * @return Char
     */
    protected function nextChar(){
        if ($this->hasInput()){
        	$this->col++;
            return $this->input[$this->position++];
        }else
            return '-1';
    }
    
	/**
     * Retorna o caractere anterior
     * @return Char
     */
    protected function prevChar(){
        if ($this->position>0)
            return $this->input[$this->position--];
        else
            return '-1';
    }
    
	/**
     * Retorna o caractere
     * @return Char
     */
    protected function getChar(){
    	if($this->position>=0&&$this->position<strlen($this->input)){
    		return $this->input[$this->position];
    	}else{
    		return '-1';
    	}
    }
    
    /**
     * Retorna o caractere
     * @return Char
     */
    protected function getCharIn($pos){
    	if($pos>=0&&$pos<strlen($this->input)){
    		return $this->input[$this->position];
    	}else{
    		return '-1';
    	}
        
    }
    
    protected function getPrevChar(){
    	if($this->position>=0){
    		return $this->input[$this->position-1];
    	}else{
    		return '-1';
    	}
        
    }
    

} // End Token